package com.itgaoshu.hospitalproject.mapper;

import com.itgaoshu.hospitalproject.bean.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface DrugstoreMapper {
    List<Drugstore> selectAllDrugstoreList();
    @Update("update drugstore set drugstoreName=#{drugstoreName},\n" +
            "    unit=#{unitId} , tradePrice=#{tradePrice} , sellingPrice=#{sellingPrice} ,\n" +
            "area=#{areaId} , type=#{typeId} ,\n" +
            "drugstorenum=#{drugstorenum},  batch=#{batch} where rugstoreId=#{rugstoreId}")
    int updateDrugstore(Drugstore drugstore);
    //查询药品类型
    @Select("select * from type")
    List <Type> seltype(Type type);
    //查询药品类型
    @Select("select * from area")
    List <Area> selarea(Area area);
    //查询药品类型
    @Select("select * from unit")
    List <Unit> selunit(Unit unit);
    //经办人
    @Select("select skullId,skullName from skull")
    List <Skull> selskull(Skull skull);
    //供货商
    @Select("select supplierId,supplierName from upplier")
    List <Upplier> selupplier(Upplier upplier);
    //仓库
    //插入入库单
    int insertrukudan(Caigou caigou);
    //加入仓库时先查看有没有该药品及该药品的数量
    @Select("select count(*) from caigou where caigouname=#{caigouname}")
    int selectCountyaopin(Caigou caigou);
    //更改仓库里的数量
    @Update("update caigou set shuliang=(shuliang+#{shuliang}) where caigouname=#{caigouname}")
    int updateshuliang(int shuliang);

    //修改药品信息
    @Update("update drugstore set drugstoreName=#{drugstoreName},\n" +
            "    unit=#{unitId} , tradePrice=#{tradePrice} , sellingPrice=#{sellingPrice} ,\n" +
            "area=#{areaId} , type=#{typeId} ,\n" +
            "drugstorenum=#{drugstorenum},  batch=#{batch} where rugstoreId=#{rugstoreId}")
    int updrugstore(Drugstore drugstore);
    //数量过少的药品查询
    List<Drugstore> selectlackdrug(Drugstore drugstore);
    //库存不足的药品有多少条
    int selcountless();
    //添加采购单
    @Update("insert into caigou(caigouname,gonghuoshang,danwei,candi,leixing,shuliang)\n" +
            "values (#{caigouname},#{gonghuoshang},#{danwei},#{candi},#{leixing},#{shuliang})")
    int addcaigou(Caigou caigou);
    //添加采购单时判断采购单是否已经有同名药品
    @Select("select count(*) from  caigou where caigouname=#{caigouname}")
    int selcaigouname(Caigou caigou);
    //添加采购单时如果已存在此药品 则直接加数量
    @Update("update caigou set shuliang =(shuliang+#{shuliang}) where caigouname=#{caigouname}")
    int upcaigounumber(Caigou caigou);
    @Select("select * from warehuose")
    List <Warehuose> selwarehuose(Warehuose warehuose);
    //查询采购表单
    @Select("select * from caigou")
    List<Caigou> selcaigou(Caigou caigou);
    //删除采购单
    @Update("delete from caigou where caigouid=#{caigouid}")
    int delcaigou(Integer caigouid);
    //查询过期的药品
    List<Drugstore> seldrugDate(Drugstore drugstore);
    //查询过期的药品有几条
    int selcountlessnum();
    //删除过期药品
    @Update("delete from drugstore where rugstoreId =#{rugstoreId};")
    int delguoqidurg(Integer rugstoreId);


}
